package iris_service

import (
	"beta/pkg/e"
	"beta/pkg/util"
	"time"
)

type IrisService struct {
	TraceId string
}

type ConfigItem struct {
	Name string `json:"name"`
	Value string `json:"value"`
	Comment string `json:"comment"`
}

type Config struct {
	ConfigID int `json:"configId"`
	ConfigItems []ConfigItem `json:"configItems"`
}

func (i IrisService) AddConfigItem(customerId string) error {
	httpClient := util.NewHttpClient(3 * time.Second).R()

	var loginData =  map[string]string{
		"loginName": "qqy",
		"password": "090025servyou",
	}
	_, loginErr := httpClient.SetHeaders(e.GetHeaderMap(e.UrlEncodeHeader)).
		SetFormData(loginData).
		Post("http://192.168.150.165:9002/servyconf/rest/auth/signin.do")

	if loginErr != nil {
		return loginErr
	}
	
	var configItems []ConfigItem
	configItem := ConfigItem{
		Name:    "white.list",
		Value:   customerId,
		Comment: "",
	}
	
	configItems = append(configItems, configItem)
	
	c := Config{
		ConfigID:    19411,
		ConfigItems: configItems,
	}

	_, configErr := httpClient.SetHeaders(e.GetHeaderMap(e.JsonHeader)).SetBody(c).
		Post("http://192.168.150.165:9002/servyconf/rest/web/config/file/updateConfigFileItem.do")

	if configErr != nil {
		return configErr
	}

	return nil
}

